/*****************************************************************************
 *   Copyright 2011 ZHUANG Yuan              	                             *
 *   SudokuITS as Final Year Project for BScCS, City University of Hong Kong *
 *                                      									 *
 *   Licensed under the Apache License, Version 2.0 (the "License");         *
 *   you may not use this file except in compliance with the License.        *
 *   You may obtain a copy of the License at                                 *
 *                                                                           *
 *   http://www.apache.org/licenses/LICENSE-2.0                              *
 *                                                                           *
 *   Unless required by applicable law or agreed to in writing, software     *
 *   distributed under the License is distributed on an "AS IS" BASIS,       *
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.*
 *   See the License for the specific language governing permissions and     *
 *   limitations under the License.                                          *
 *****************************************************************************/

package android.sudoku.its.expert;

import java.util.List;

public class Expert {
	private CandidateMatrix cm;
	private ApplicableStrategyMatrix asm;
	
	public Expert(int[][] twoDClues) {
		// initialize candidate graph
		cm = new CandidateMatrix(twoDClues);	
		asm = new ApplicableStrategyMatrix(twoDClues, cm.getCandidateMatrix());
	}
	
	/**
	 * Update the Candidate Matrix and the Applicable Strategy Matrix in the expert model
	 * when a number is input by the user
	 * @param num		the number input by the user
	 * @param nRow		the row index of the input position
	 * @param nCol		the column index of the input position
	 * @param clues		a 2d array representing current clues on the game board AFTER THE INPUT HAPPENED
	 */
	public void updateWorkingMemory(int num, int[][] clues) {		
		cm.generateCandidateMatrix(clues);
		asm.generateApplicableStrategyMatrix(clues, cm.getCandidateMatrix());
	}
	
	public void updateExpertForNakedPair(int[] candidatesToBeRemoved, int[] nakedPairCellIndexes, int[][] clues) {
		cm.updateCandidateMatrixForNakedPair(candidatesToBeRemoved, nakedPairCellIndexes);
		asm.generateApplicableStrategyMatrix(clues, cm.getCandidateMatrix());
	}
	
	public void updateExpertForHiddenPair(int[] candidateToBeRetained, int[] hiddenPairCellIndexes, int[][] clues) {
		cm.updateCandidateMatrixForHiddenPair(candidateToBeRetained, hiddenPairCellIndexes);
		asm.generateApplicableStrategyMatrix(clues, cm.getCandidateMatrix());
	}
	
	public List<Integer> getApplicableStrategyForCell(int nRow, int nCol) {
		return asm.getApplicableStrategyByCellFunc(nRow, nCol);
	}
	
	public List<List<Integer>> getApplicableStrategyMatrix() {
		return asm.getApplicableStrategyMatrix();
	}
	
	public List<List<Integer>> getCandidateMatrix() {
		return cm.getCandidateMatrix();
	}	
	
	public int[][] getCm() {
		return cm.getIntArrCandidateMatrix();
	}
	
	public int[][] getAsm() {
		return asm.getIntArrAsm();
	}
	
}
